package com.wondersgroup.framework.sample.component.form.action;

import com.wondersgroup.framework.core.web.struts2.action.BaseAjaxAction;
import com.wondersgroup.framework.core.web.vo.VOUtils;
import com.wondersgroup.framework.sample.component.form.vo.CodeInfoVO;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class CodeInfoAction extends BaseAjaxAction
{
  List<CodeInfoVO> codeInfoData;

  public CodeInfoAction()
  {
    this.codeInfoData = new ArrayList();
  }

  public String loadCodeInfo()
  {
    Iterator i$;
    CodeInfoVO model;
    this.codeInfoData = getCodeInfoData();
    List result = new ArrayList();

    String parentValue = super.getServletRequest().getParameter("parentValue");

    if ((parentValue == null) || (parentValue.equals("")))
      for (i$ = this.codeInfoData.iterator(); i$.hasNext(); ) { model = (CodeInfoVO)i$.next();
        if (model.getParent() == null)
          result.add(model);

      }

    else
      for (i$ = this.codeInfoData.iterator(); i$.hasNext(); ) { model = (CodeInfoVO)i$.next();
        if ((model.getParent() != null) && (model.getParent().getCode().equals(parentValue)))
          result.add(model);
      }

    String json = VOUtils.getJsonDataFromCollection(result);
    createJSonData(json);
    return "ajax";
  }

  public List<CodeInfoVO> getCodeInfoData() {
    return ((List)getServletRequest().getSession().getServletContext().getAttribute("codeInfoList"));
  }

  public void setCodeInfoData(List<CodeInfoVO> codeInfoData) {
    getServletRequest().getSession().getServletContext().setAttribute("codeInfoList", codeInfoData);
  }
}
